package com.lxp.project.generator.service.impl;

import com.lxp.common.core.text.Convert;
import com.lxp.project.generator.domain.GenTableColumn;
import com.lxp.project.generator.mapper.GenTableColumnMapper;
import com.lxp.project.generator.service.IGenTableColumnService;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 业务字段 服务层实现
 *
 * @author lxp
 */
@Service
public class GenTableColumnServiceImpl extends ServiceImpl<GenTableColumnMapper, GenTableColumn> implements IGenTableColumnService {

    /**
     * 查询业务字段列表
     *
     * @param tableId 业务字段编号
     * @return 业务字段集合
     */
    @Override
    public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId) {
        QueryWrapper lqw = new QueryWrapper();
        lqw.eq(GenTableColumn::getTableId, tableId);
        lqw.orderBy(GenTableColumn::getSort,true);
        return this.list(lqw);
    }

    /**
     * 删除业务字段对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteGenTableColumnByIds(String ids) {
        Long[] longArray = Convert.toLongArray(ids);
        List<Long> list = Arrays.asList(longArray);
        return mapper.deleteBatchByIds(list);
    }
}
